/**
 * 配置编辑器类型定义
 * 与服务器端配置类型保持同步
 */

// === 基础类型 ===
export interface BaseConfig {
  id: string
  name: string
  description?: string
  version?: string
  enabled?: boolean
  tags?: string[]
  lastModified?: number
  author?: string
}

// === 技能配置 ===
export interface SkillConfig extends BaseConfig {
  skillId: string
  reName?: string
  desc?: string
  type?: 'active' | 'passive' | 'aura'
  targetTypes?: string[]
  cooldown?: number
  level?: number
  maxLevel?: number
  exp?: number
  useCount?: number
  quality?: number
  category?: string
  classType?: string
  notBuy?: boolean
  effects?: string[]
  effect?: string[]
  data?: ISkillEffectData[]
  permanentBoost?: IPermanentBoostConfig
  buffs?: IBuffConfig[]
  triggerConditions?: Record<string, any>
  prerequisites?: string[]
  customData?: Record<string, any>
}

export interface ISkillEffectData {
  attRange?: number
  fixed?: number
  shield?: number
  healing?: number
  attributeModify?: Record<string, number>
  statusEffect?: IStatusEffectConfig
  permanentBoost?: IPermanentBoostConfig
  [key: string]: any
}

export interface IPermanentBoostConfig {
  type: string
  amount: number
  maxBoosts?: number
  condition?: string
  conditionParams?: Record<string, any>
  conditionDesc?: string
}

export interface IBuffConfig {
  id: string
  duration: number
  maxStacks?: number
  value?: number
}

export interface IStatusEffectConfig {
  type: string
  duration: number
  intensity?: number
}

// === 装备配置 ===
export interface EquipmentTemplate extends BaseConfig {
  sys: string
  type: string
  job: string
  solt: string
  icon: string
  emoji: string
  source?: string
  quality: {
    min: number
    max: number
    weights?: number[]
  }
  baseAttributes: AttributeConfig[]
  skillPools: SkillPools
  creator?: string
}

export interface AttributeConfig {
  key: string
  min: number
  max: number
  growthType?: 'linear' | 'exponential' | 'logarithmic'
  qualityMultiplier?: number
}

export interface SkillPools {
  inherent: SkillConfig[]
  enchantable: EnchantableSkillPool[]
  exclusive?: ExclusiveSkillUnlock[]
}

export interface EnchantableSkillPool {
  skill: SkillConfig
  weight: number
  conditions?: EnchantCondition
  maxCount?: number
}

export interface EnchantCondition {
  minLevel?: number
  requiredTalent?: string
  requiredQuest?: string
  customCheck?: string
}

export interface ExclusiveSkillUnlock {
  skill: SkillConfig
  unlock: {
    type: 'quest' | 'achievement' | 'event' | 'custom'
    requirement: string
    description?: string
  }
}

// === 配置集合 ===
export interface ConfigCollection<T = any> {
  version: string
  lastUpdated: number
  data: T[]
  metadata?: {
    author?: string
    description?: string
    changelog?: string[]
  }
}

// === 验证结果 ===
export interface ValidationResult {
  isValid: boolean
  errors: ValidationError[]
  warnings: ValidationWarning[]
  validatedCount: number
}

export interface ValidationError {
  id: string
  field?: string
  message: string
  severity: 'error' | 'warning' | 'info'
}

export interface ValidationWarning extends ValidationError {
  suggestion?: string
}

// === API 相关类型 ===
export interface ApiResponse<T = any> {
  success: boolean
  data?: T
  message?: string
  errors?: string[]
}

export interface ConfigListItem {
  type: string
  name: string
  description: string
  count: number
  lastModified: number
  size: string
  status: 'healthy' | 'warning' | 'error'
}

// === 编辑器状态 ===
export interface EditorState {
  isLoading: boolean
  isDirty: boolean
  lastSaved?: number
  autoSave: boolean
  validationEnabled: boolean
}

// === 导入导出 ===
export interface ImportOptions {
  format: 'xlsx' | 'json' | 'yaml'
  merge?: boolean
  validate?: boolean
  backup?: boolean
}

export interface ExportOptions {
  format: 'xlsx' | 'json' | 'yaml' | 'typescript'
  minify?: boolean
  includeComments?: boolean
  selectedTypes?: string[]
}

// === 搜索和过滤 ===
export interface SearchCriteria {
  keyword?: string
  type?: string
  category?: string
  tags?: string[]
  quality?: number
  level?: { min?: number; max?: number }
  enabled?: boolean
}

export interface SortOptions {
  field: string
  direction: 'asc' | 'desc'
}

// === 编辑器配置 ===
export interface EditorConfig {
  theme: 'light' | 'dark'
  autoSave: boolean
  autoSaveInterval: number
  validationEnabled: boolean
  showLineNumbers: boolean
  wordWrap: boolean
  fontSize: number
  language: 'zh-CN' | 'en-US'
}

// === 统计信息 ===
export interface ConfigStats {
  totalConfigs: number
  configsByType: Record<string, number>
  lastModified: number
  healthStatus: 'healthy' | 'warning' | 'error'
  validationScore: number
  memoryUsage?: string
}
